package com.tritrees.easygridview.widget;

import java.util.HashMap;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;



public class AddEasyGridView extends EasyGridView
{

	public AddEasyGridView(Context context, AttributeSet attrs)
	{
		super(context, attrs);
	}

	@Override
	protected void initAdapterData()
	{
		int num = 0;
		HashMap<String, Object> map;
		dataList.clear();

		for (int i = 0; i < data.size(); i++)
		{
			dataList.add(data.get(i));
		}

		map = new HashMap<String, Object>();
		map.put(EasyGridView.IMAGE, bmp_add);
		dataList.add(map);
		num = dataList.size();
		addBlankItem(num);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	{
		if(position == dataList.size() - blankItemCount - 1)
		{
			if (isChildItem)
			{
				if (handleGridViewWithChild != null)
				{
					handleGridViewWithChild.addImage(childPosition);
				}
			} else
			{
				if (handleGridView != null)
				{
					handleGridView.addImage();
				}
			}
			updateAdapter();
		}else if(position < dataList.size() - blankItemCount - 1)
		{
			if (isChildItem)
			{
				if (handleGridViewWithChild != null)
				{
					handleGridViewWithChild.queryImage(childPosition,
							position);
				}
			} else
			{
				if (handleGridView != null)
				{
					handleGridView.queryImage(position);
				}
			}
		}
	}

}
